﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Clipper.Model;
using System.Threading;
using Global;
using System.Windows;

namespace Clipper.BLL.DetectChain
{
    /// <summary>
    /// 回收仓
    /// </summary>
    public class RecycleBin:ApplianceComponent
    {
        #region 变量
        static System.Timers.Timer mTimerCountDown = new System.Timers.Timer();//倒计时
        static DateTime mdtStart;
        #endregion
        
        #region 属性
        static ControlStatusEnum detectionStatus;
        /// <summary>
        /// 状态
        /// </summary>
        public override ControlStatusEnum DetectionStatus
        {
            get
            {
                return detectionStatus;
            }
            set
            {
                detectionStatus = value;
            }
        }
        static bool mIsPause=false;
        /// <summary>
        /// 获得或设置模块暂停状态
        /// </summary>
        public static bool IsPause
        {
            get
            {
                return mIsPause;
            }
        }

        #endregion

        #region 初始化 
        public RecycleBin()
        {
            mTimerCountDown.Elapsed += new System.Timers.ElapsedEventHandler((ss, ee) =>
            {
                TimeSpan ts = mdtStart - DateTime.Now;

                if (ts < TimeSpan.Zero)
                {
                    ServiceProvider.Monitor.NextResultCD = "00:00";
                    mTimerCountDown.Stop();
                }
                else
                {
                    ServiceProvider.Monitor.NextResultCD = string.Format("{0:D2}:{1:D2}", ts.Minutes, ts.Seconds);
                }
            });
            mTimerCountDown.Interval = 1000;
        }
        #endregion

        public override void Run(ReactionCup strip)
        {
           // strip.Note = "---end---" + Thread.CurrentThread.Name + "--" + strip.ID;
           // Console.WriteLine(strip.Note);
           // detectionStatus = ControlStatusEnum.BUSY;
           //// strip.ReactionStripSeat = ReactionStripStageEnum.RECYCLEBIN;

           // if (ServiceProvider.IsSimulate)
           // {
           //     Simulate(strip);
           // }
           // else
           // {
           //     //mCompleteReset.WaitOne();
           // }
           // detectionStatus = ControlStatusEnum.IDLE;
           // if (ServiceProvider.gReactionStripList.Count == 0 && ServiceProvider.Monitor.RunningStrips.Count == 0)//检测完成
           // {
           //     mdtStart = DateTime.Now;
           //     DetectChainHelper.mdtStart = DateTime.Now;
           //     ServiceProvider.Monitor.IsRunning = false;
                
           //     ServiceProvider.WaitMessage.Add(4000);
           //     AddReagent1AndSample.SA.MainClose();
           //     IncubationBox.BedControl.StopRock();
           //     AddReagent1AndSample.PumpControl.Close();
                
           // }
           // else
           // {
           //     mdtStart = DateTime.Now.AddSeconds(90);
           //     mTimerCountDown.Start();
           // }
        }
        public override void Simulate(ReactionCup strip)
        {
            Thread.CurrentThread.Abort();
        }

    }
}
